using AndyPike.Commons;
using AndyPike.Commons.Extensions;
using AndyPike.Snowflake.Core.Exceptions;

namespace AndyPike.Snowflake.Core.Messages
{
    public class CredentialsMessage : IMessage
    {
        private string password;

        public string UserName { get; set; }

        public string Password
        {
            get { return password != null ? password.ToMD5() : password; }
            set { password = value; }
        }

        public virtual void Validate()
        {
            if (string.IsNullOrEmpty(UserName))
                throw new InvalidUserNameException();

            if (string.IsNullOrEmpty(Password))
                throw new InvalidPasswordException();
        }
    }
}